import 'package:flutter/material.dart';
import '../view/login_top_view.dart';
import '../view/login_center_view.dart';
import '../../main.dart';
import '../../manger/qysdk_manger.dart';
import '../../manger/umevent_utils.dart';

class LoginView extends StatefulWidget {
  const LoginView({super.key});

  @override
  State<LoginView> createState() => _LoginViewState();
}

class _LoginViewState extends State<LoginView> {
  @override
  void initState() {
    super.initState();
    UmengEvent.trackEvent("login_launch","进入登录页","");
  }

  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: true,
      onPopInvokedWithResult: (didPop, result) {
      if (!didPop) {
        pushMainPage();
      }
    },
      child: Scaffold(
        body: Container(
          color: const Color(0xffF5F5F5),
          child: Stack(
            children: [
              Positioned(
                top: 0,
                left: 0,
                right: 0,
                child: SizedBox(
                  height: 260,
                  child: LoginTopView(
                    onBack: () {
                      pushMainPage();
                    },
                    onHelp: () {
                      QYSDK.showQYSession();
                    },
                    type: 1,
                  ),
                ),
              ),
              Positioned(
                top: 215,
                left: 25,
                right: 25,
                height: 500,
                child: LoginCenterView(
                  onLoginSuccess: () {
                    pushMainPage();
                  },
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Future<void> pushMainPage() async {
    Navigator.pushReplacement(
      context,
      MaterialPageRoute(
        builder: (context) => MainPage(),
      ),
    );

  }
}
